package com.dataaccess.dataaccess.web.web;

import cn.hutool.json.JSONObject;
import com.dataaccess.dataaccess.common.base.BaseController;
import com.dataaccess.dataaccess.common.utils.appkit.FirefightingiotKit;
import com.dataaccess.dataaccess.config.rocketmq.UserProducer;
import com.dataaccess.dataaccess.model.AlarmAllDeviceDataChanged;
import com.dataaccess.dataaccess.support.utils.MyLogger;
import com.dataaccess.dataaccess.web.mapper.AlarmAllDeviceDataChangedMapper;
import com.dataaccess.dataaccess.web.service.VisualizationVideoAlarmService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @Author: YangYu
 * @ClassName: DeviceDataAsyncController
 * @Date: Created in 10:31 2021/11/16
 * @Description: 收到设备数据异步处理
 */
@Service
public class DeviceDataAsyncController extends BaseController {

    @Resource
    public MyLogger logger;
    @Resource
    private VisualizationVideoAlarmService videoAlarmService;
    @Resource
    private AlarmAllDeviceDataChangedMapper alarmAllDeviceDataChangedMapper;
    @Resource
    UserProducer userProducer;

    /**
     * @Author YangYu
     * @Description 异步处理消控宝数据
     * @Date Created in 10:35 2021/11/16
     * @Param [jsonParam]
     */

    @Async
    public JSONObject aliyunAsyncCamera(JSONObject jsonParam) throws Exception {
        logger.info("aliyunAsyncCamera" + "------" + jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        jsonParam.put("deviceFlag", "aliyunCamera");
        String mqFlag = FirefightingiotKit.getStr("mqFlag", "mq");
        if (mqFlag.equals("1")) {
            return videoAlarmService.aliyunCamera(jsonParam);
        }else if(mqFlag.equals("3")){
            userProducer.produder(jsonParam.toString());
        }
        JSONObject ret = new JSONObject();
        ret.put("errcode", 0);
        ret.put("errmsg", "ok");
        return ret;
    }
}
